package cs.uns.edu.ar.aygps.view;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;

import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

import sun.misc.Cleaner;

@SuppressWarnings("serial")
public class LeftPanel {
	
	protected JDesktopPane thePanel;
	JButton clientButton;
	static JScrollPane scroll;
	
	
	
	
	public LeftPanel(JDesktopPane panel) {
		JTree clientTree = new ClientTree(); 
		expandAll(clientTree, true);
		clientTree.setEnabled(false);
		
		scroll = new JScrollPane(clientTree);
		
		thePanel = panel;
		scroll.setBackground(Color.LIGHT_GRAY);

		
//		ImageIcon clientIcon = new ImageIcon("/AyGPS/AyGPS-View/resources/image/customers.gif");
//		clientButton = new JButton(clientIcon);
//		JLabel clientLabel = new JLabel("Clientes");
//		add(clientButton);
//		add(clientLabel);
		
	
	}
	
	public JScrollPane getPanel(){
		return scroll;
	}
	
	public void expandAll(JTree tree, boolean expand) {
        TreeNode root = (TreeNode)tree.getModel().getRoot();
    
        // Traverse tree from root
        expandAll(tree, new TreePath(root), expand);
    }
    private void expandAll(JTree tree, TreePath parent, boolean expand) {
        // Traverse children
        TreeNode node = (TreeNode)parent.getLastPathComponent();
        if (node.getChildCount() >= 0) {
            for (Enumeration e=node.children(); e.hasMoreElements(); ) {
                TreeNode n = (TreeNode)e.nextElement();
                TreePath path = parent.pathByAddingChild(n);
                expandAll(tree, path, expand);
            }
        }
    
        // Expansion or collapse must be done bottom-up
        if (expand) {
            tree.expandPath(parent);
        } else {
            tree.collapsePath(parent);
        }
    }

}
